import * as feedback from "/@//components/feedback/index.js";

export class Button {
    constructor(click, visible = () => true, loading = false) {
        this.click = click;
        this.visible = visible;

    }
}

const buttons = {
    add: new Button((context, instance) => {
        context.title = '新增';
        context.visible = true;
    }),
    edit: new Button((context, instance) => {
        context.title = '修改';
        context.visible = true;
        context.form = {
            demo: '测试'
        };
    }),
    save: new Button((context, instance) => {
        context.validate((valid, fields) => {
            if (valid) {
                context.load();
            }
        })
    }),
    remove: new Button((context, instance) => {
        feedback.loading();
        feedback.confirm('确定要删除当前数据？').then(r => {
            console.log(r);
        });

        setTimeout(() => {
            feedback.close();
        }, 2000)
    }),
    cancel: new Button((context, instance) => {
        context.visible = false;
        context.reset();
        context.clear();
    }),
}

export default buttons;

